/**
 * 删除上传的图片
 */
function deleteCover(value) {
    $("#" + value).remove();
}

/**
 * 会员
 */

define([
    'jquery',
    'baseUtils',
    'base',
    'msgTool',
    'css!global/plugins/wangEditor/wangEditor.min.css',
    'plugins/wangEditor/wangEditor.min',
    'css!global/plugins/fileInput/fileinput.min.css',
    'plugins/fileInput/fileinput.min',
    'plugins/bootstrap-table/bootstrap-table',
    "plugins/bootstrap-dialog/bootstrap-dialog",
    "css!global/plugins/bootstrap-dialog/bootstrap-dialog.css"
], function ($, baseUtils, base, msgTool, _, E, _, _, _, BootstrapDialog) {
    //默认加载基础库
    base();
    //执行
    return {
    	 info: function () {                   

             /**
              * 提交食药设备申请
              */

             $("#submitDevice").on('click', function () {
            	 var reg_number = /^(0|[1-9]\d*)$/;//验证数字
              	 var deviceName = $("#deviceName").val();
           	     var number=$("#number").val();
           	     var site=$("#site").val();
               if(deviceName==''){
              	$("#deviceName-error").html("(设备名称不能为空)");
              	return false;
               }else{
            	$("#deviceName-error").html("");   
               }
               if(number==''){
           	   $("#number-error").html("(设备数量不能为空)");
           	   return false;
               }else{
            	   if (!reg_number.test(number)){
                		  $("#number-error").html("(请输入正确的证件号码)");
       					return false;
       				}else{
       				  $("#number-error").html("");	
       				}
               }
               if(site==''){
                $("#site-error").html("(设备位置不能为空)");
                return false;
               }else{
                $("#site-error").html("");
               }
               $("#saveDeviceForm").submit();
              });
             
             $("#cancelDevice").on('click', function () {
            	 var applyId=$("#applyId").val();
            	 var changeId=$("#changeId").val();
            	 if(changeId==undefined){
            		 window.location.href="/fooddrugApply/deviceList?applyId="+applyId;
            	 }
            	 if(applyId==undefined){
            		 window.location.href="/fooddrugChange/deviceList?changeId="+changeId;
            	 }
             });
             
      
             
           
         },

    	 /**
         * 列表
         */
        list: function () {

            var myTable = $('#deviceList');
            var tableRefresh = function () {
                myTable.bootstrapTable('refresh', {url: 'device/api.json'})
            };

            //table当前行的响应事件
            window.operateEvents = {
                'click .update': function (e, value, row) {
                    winModal("编辑", row);
                },
                'click .status': function (e, value, row) {
                    $.baseUtils.oneStatus({
                        row: row,
                        tableName: myTable,
                        nameText: '设备名称',
                        nameValue: row.deviceName,
                        url: '/user/project/status/action'
                    });
                },
                'click .delete': function (e, value, row) {
                    $.baseUtils.oneDelete({
                        row: row,
                        tableName: myTable,
                        nameText: '设备名称',
                        nameValue: row.deviceName,
                        url: '/fooddrug/deleteDevice/action'
                    });
                }
            };

            //table表格
            myTable.bootstrapTable({
                url: 'device/api.json', // 接口 URL 地址
                cache: false, // 不缓存
                striped: true, // 隔行加亮
                pagination: true, // 开启分页功能
                sidePagination: 'server',//服务端分页
                sortOrder: 'desc', // 设置排序为反序 desc
                fixedColumns: true,//自动修复
                queryParams:queryParams,//搜索附加参数
                smartDisplay: false, // 智能显示 pagination 和 cardview 等
                toolbar: ".toolBar", //顶部工具菜单
                toolbarAlign: "right", //顶部工具位置
                mobileResponsive: "true", //手机模式自适应宽度（自动变成卡片模式）
                columns: [
                    {
                        field: 'rowno',
                        title: '序号',
                        formatter: function (value, row, index) {  
                            return index+1;  
                        },  
                        align: 'center'
                    }, {
                        field: 'deviceName',
                        title: '设备名称',
                        align: 'center'
                    },  {
                        field: 'number',
                        title: '数量',
                        align: 'center'
                    }, {
                        field: 'site',
                        title: '位置',
                        align: 'center'
                    }, {
                        field: 'action',
                        title: '操作',
                        align: 'center',
                        formatter: operateFormatter,
                        events: operateEvents
                    }
                ]
            });
            //查询条件  
            function queryParams(params) {  
            	var applyId=$("#applyId").val();
            	var changeId=$("#changeId").val();
            	if(changeId==undefined){
            		return {  
            			applyId:applyId
            		};  
            	}
            	if(applyId==undefined){
            		return {  
            			changeId:changeId
            		};  
            	}
            }  
            
            $("#submitApply").on('click', function () {
    			if(!$('#checkbox').is(':checked')) {
    				msgTool.success("请勾选我已同意《食品安全管理制度》","信息提示");
    			}else{
    		           $.ajax({
                           url: "/fooddrugApply/saveApply",
                           method: "POST",
                           dataType: "json",
                           data: {
                        	   id:$("#applyId").val(),
                               applyStatus: 1
                           },
                           success: function (data) {
                                window.location.href="/user/transact";
                                msgTool.success("提交成功！","信息提示");
                           },
                           error: function (jqXHR) {
                               msgTool.error(jqXHR.status + " (" + jqXHR.statusText + ")", "错误提示");
                               return false;
                           }
                       })
    			
    			}
            });
            
            $("#submitChange").on('click', function () {
                $.ajax({
                    url: "/fooddrugChange/saveApply",
                    method: "POST",
                    dataType: "json",
                    data: {
                 	   id:$("#changeId").val(),
                       applyStatus: 1
                    },
                    success: function (data) {
                         window.location.href="/user/transact";
                         msgTool.success("提交成功！","信息提示");
                    },
                    error: function (jqXHR) {
                        msgTool.error(jqXHR.status + " (" + jqXHR.statusText + ")", "错误提示");
                        return false;
                    }
                })
            });
            
        },

        /**
         * 查看
         */
        view: function () {

        },

        /**
         *编辑保存
         */
        save: function () {
            

        }
    }
});


